package cn.cvs.service.storageRecord;

import cn.cvs.dao.StroageRecordMapper;
import cn.cvs.pojo.StorageRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StroageRecordServiceImpl implements StroageRecordService {
    @Resource
    private StroageRecordMapper stroageRecordMapper;


    @Override
    public List<StorageRecord> findStorageList(String queryGoodsName, Integer querySupplierId, Integer queryPayStatus, Integer pageIndex, Integer pageSize) throws Exception {
        return stroageRecordMapper.queryAllStroageList(queryGoodsName, querySupplierId, queryPayStatus, (pageIndex - 1) * pageSize, pageSize);
    }

    @Override
    public int findCount(String queryGoodsName, Integer querySupplierId, Integer queryPayStatus) throws Exception {
        return stroageRecordMapper.queryCount(queryGoodsName, querySupplierId, queryPayStatus);
    }

    @Override
    public boolean addStorageRecord(StorageRecord storageRecord) throws Exception {
        if (stroageRecordMapper.insertStorageRecord(storageRecord) > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean updateStorageRecord(StorageRecord storageRecord) throws Exception {
        if (stroageRecordMapper.modifyStorageRecord(storageRecord) > 0) {
            return true;
        }
        return false;
    }

    @Override
    public StorageRecord findStorageRecordById(Integer id) throws Exception {
        return stroageRecordMapper.queryStorageRecordById(id);
    }

    @Override
    public boolean deleteStorageRecordById(Integer id) throws Exception {
        if (stroageRecordMapper.delStorageRecordById(id)>0){
            return true;
        }

        return false;
    }

    @Override
    public List findStorageRecordBySupplierId(Integer id) throws Exception {
        return stroageRecordMapper.findStorageRecordBySupplierId(id);
    }
}
